﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Commonlib;
namespace AlbonWeb.Manager.AccountManager
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
                //绑定角色信息
                string cmdstr = "select * from RoleInfo where active=1";
                SqlHelper.BindDropDownList(ddlRole, "roleName", "ID",SqlHelper.SqlConnectionString,CommandType.Text, cmdstr, null);
                ddlRole.Items.Insert(0, new ListItem("--select role--", "0"));

                //绑定用户信息
                ViewState["limit"] = " where 1=1";
                bindUser();
            }
        }
        //绑定用户
        private void bindUser()
        {
            if (ddlRole.SelectedIndex!=0)
            {
                ViewState["limit"] += " and roleID =" + ddlRole.SelectedValue;
            }
            if (userName.Text.Trim() != "")
            {
                ViewState["limit"] += " and userName like '%" + userName.Text.Trim() + "%'";
            }
            string cmdstr = "select count(*) from UserView " + ViewState["limit"].ToString();
            AspNetPager1.RecordCount = int.Parse(SqlHelper.ExecuteScalar(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).ToString());
            SqlParameter[] parameters = new SqlParameter[]{
                new SqlParameter("@tablename","UserView"),
                new SqlParameter("@startIndex",AspNetPager1.StartRecordIndex),
                new  SqlParameter("@endIndex",AspNetPager1.EndRecordIndex),
                new SqlParameter("@limit",ViewState["limit"].ToString()),
                new SqlParameter("@orderby","createDate desc")
            };
            SqlHelper.BindRepeater(repMain, SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "netpager", parameters);
        }

        //搜索
        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            ViewState["limit"]=" where 1=1";
            bindUser();
        }
        //换页 
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
          
            
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            bindUser();
        }
    }
}